<?php

class Content extends Controller {

	function __construct()
	{
		parent::Controller();
		$this->load->model('Category_model');
		$this->load->model('Customer_model');
	}
	
	function index()
	{
		$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "The Perfect gift for your little Bambino";
		
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('store/main');
		$this->load->view('common/footer');
	}
	function contact()
	{
		$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "Contact Us";
		$data['current_page'] = "Contact";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/contact');
		$this->load->view('common/footer');
	}
	function sendmsg() {
		$firstname = $this->input->post('firstname',true);
		$familyname = $this->input->post('familyname',true);
		$storelocation = $this->input->post('storelocation',true);
		//$email = $this->input->post('email',true);
		$phone = $this->input->post('phone',true);
		$msg = $_POST['msg'];
		$message = sprintf("
		
7 Eleven Online Merchandise Store Contact Form

First Name: %s
Family Name: %s
Store Location: %s
Phone: %s
Message:
%s

7 Eleven Online Merchandise Store
		",$firstname,$familyname,$storelocation,$phone,$msg);
	
		$this->load->library('email');
		
		$this->email->from('noreply@onlinemerchandise.com.au','7 Eleven Online Merchandise Store');
		$this->load->model('System_model');
		$emailc = $this->System_model->get_email('name','contact');
		$email_c = json_decode($emailc['address'],true);
		
		
		if ($email_c) 
		{
			$this->email->to($email_c[0]);
			if(count($email_c) > 1)
			{
			 for($i=1;$i<count($email_c);$i++) 
			 {
				$this->email->cc($email_c[$i]);
			 }
			}
		} else {
			$this->email->to('24-7support@7eleven.com.au');
		}
		
		$this->email->subject('7 Eleven Online Merchandise Store Contact Form');
		$this->email->message($message);
		if($this->email->send())
		{
		 $this->session->set_flashdata('send_msg','Your contact message has been successfully sent');
		}
		else
		{
			 $this->session->set_flashdata('send_msg','There was error sending your contact message. Please try again!');
		}
		redirect('contact');
	}
	function subscribe() {
		if($_POST['email2'] != '')
		{
		$this->load->model('Subscribe_model');
		$firstname = $this->input->post('firstname2',true);
		$familyname = $this->input->post('familyname2',true);
		
		$email = $this->input->post('email2',true);
		$mobile = $this->input->post('mobile',true);
		$data = array(
		              'firstname'=> $firstname,
					  'familyname'=> $familyname,
					  'email'=> $email,
					  'mobile'=> $mobile,
					  'date' => date('Y-m-d H:i:s')
					  );
		$id = $this->Subscribe_model->add($data);
		  if($id > 0)
		  {
			$this->session->set_flashdata('subscribe_msg','You have successfully subscribed to our merchandise news');
		  }
		  else
		  {
			 $this->session->set_flashdata('subscribe_msg','There was error subscribing. Please try again!');
		  }
		}
		else
		{
			$this->session->set_flashdata('subscribe_msg','Please fill in required fields');
		}
		redirect('contact');
	}
	function ajax_subscribe() {
		if($_POST['email2'] != '')
		{
		$this->load->model('Subscribe_model');
		
		$email = $this->input->post('email2',true);
		
		$data = array(       
					  'email'=> $email,
					  'date' => date('Y-m-d H:i:s')
					  );
		$id = $this->Subscribe_model->add($data);
		  if($id > 0)
		  {
			print('You have successfully subscribed to our merchandise news');
		  }
		  else
		  {
			 print('There was error subscribing. Please try again!');
		  }
		}
		else
		{
			print('Please enter valid email');
		}
		
	}
	function return_policy()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "Company Information";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/return');
		$this->load->view('common/footer');
	}
	function terms()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "Terms & Conditions";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/terms');
		$this->load->view('common/footer');
	}
	function delivery_details()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "Delivery Details";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/delivery');
		$this->load->view('common/footer');
	}
	function faqs()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "FAQs - Frequently asked questions";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/faqs');
		$this->load->view('common/footer');
	}
	function size_chart()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['current_page'] = 2;
		$data['page_title'] = "Size Chart";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/size_chart');
		$this->load->view('common/footer');
	}
	function privacy()
	{
		//$data['categories'] = $this->Category_model->get_main();
		$data['page_title'] = "Privacy Policy";
		$this->load->view('common/header',$data);
		//$this->load->view('common/leftbar',$data);
		$this->load->view('content/privacy');
		$this->load->view('common/footer');
	}
}
?>
